//
//  ViewController.m
//  28---UIViewAnimation(2)
//
//  Created by 冀永金 on 16/8/22.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "ViewController.h"
#import "UIView+Frame.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *animationView;
@property (nonatomic, strong) UIButton *animationButton;
@property (nonatomic, strong) UIButton *animationButton1;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 约束动画
//需要改变  NSLayoutConstraint（priority,constant）
    // Massory  需要用 mas_upDataConstraints
       // Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.animationView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
    [self.view addSubview:_animationView];
    self.animationButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:_animationButton];
    _animationButton.backgroundColor = [UIColor cyanColor];
    _animationButton.frame = CGRectMake(100, 100, 200, 200);
    [_animationButton addTarget:self action:@selector(handleClick:) forControlEvents:UIControlEventTouchUpInside];
    self.animationButton1 = [UIButton buttonWithType:UIButtonTypeSystem];
    //[self.view addSubview:_animationButton1];
    _animationButton1.backgroundColor = [UIColor yellowColor];
    _animationButton1.frame = CGRectMake(100, 100, 100, 100);
    
    // 参数3：0.0~1.0 阻尼系数  数值越小 阻力越小   数值越大  阻力越大
    // 参数4：速度
    // 参数5： 选项
    self.animationView.backgroundColor = [UIColor blueColor];
    [UIView animateWithDuration:5 delay:0 usingSpringWithDamping:.5f initialSpringVelocity:15.0f options:UIViewAnimationOptionCurveLinear   animations:^{
        _animationView.yj_width = 100;
        _animationView.jy_height = 300;
    } completion:^(BOOL finished) {
        
    }];
    

}
- (void)handleClick:(UIButton *)button {
    // 参数1：需要执行动画的view
    // 参数2：持续时间
    // 参数3： 动画的效果
//    [UIView transitionWithView:_animationButton duration:5 options:UIViewAnimationOptionTransitionCurlDown animations:^{
//        _animationButton.jy_height = 100;
//    } completion:^(BOOL finished) {
//        [UIView animateWithDuration:2 animations:^{
//            _animationButton.jy_height = 200;
//        }];
//    }];
    // toView added to fromView.superview, fromView removed from its superview
    // toView会被添加到fromView的父视图上，然后fromView被移除
    [UIView transitionFromView:_animationButton toView:_animationButton1 duration:3 options:UIViewAnimationOptionTransitionFlipFromLeft   completion:^(BOOL finished) {
        
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
